package cn.bugstack.xfg.frame.test

import cn.bugstack.xfg.frame.dao.IUserDao
import cn.bugstack.xfg.frame.domain.po.User
import cn.bugstack.xfg.frame.service.impl.UserServiceImpl
import spock.lang.Specification

//
/**
 * Spock单元测试
 * <a href="https://tech.meituan.com/2021/08/06/spock-practice-in-meituan.html">Spock单元测试</a>
 */
class UserServiceSpec extends Specification {
    def dao = Mock(IUserDao)
    def service = new UserServiceImpl(userDao: dao)

    def "test getById"() {
        given:
        def s1 = new User(userId: "184172133", province: "北京")
        def s2 = new User(userId: "980765512", province: "上海")

        and:
        dao.queryUserList() >> [s1, s2]

        when:
        def res = service.queryUserInfo("184172133")

        then:
        with(res) {
            userId == "184172133"
            abbreviation == "京"
        }

    }
}
